
package com.compuvest.web;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Preference implements java.io.Serializable {

    private String title;
    private List<String> contents;
    private Map<String,Integer> countContent;

    public Preference() {
        title = "";
        contents = new ArrayList<>(70);
        countContent = new HashMap<>(70);
    }

    public int getCount(String name)    { return countContent.get(name); }

    public String getTitle()            { return title; }
    public void setTitle(String title)  { this.title = title; }

    public List<String> getBlock() {
        if(contents.isEmpty()) { return null; }
        Collections.sort(contents, new AlphanumComparator());
        return contents;
    }

    public void addContent(String word) {

        if(word == null || word.length() == 0) { return; }

        if(countContent.containsKey(word)) {
            countContent.put(word, countContent.get(word).intValue() + 1);
        }
        else {
            countContent.put(word, 1);

            contents.add(word);
        }
    }

    @Override
    public String toString() {
        return title;
    }
}
